//
//  STApplicationFormHeaderTableView.m
//  赛拓
//
//  Created by 王磊 on 8/13/16.
//  Copyright © 2016 立金所. All rights reserved.
//

#import "STApplicationFormHeaderTableView.h"
@interface STApplicationFormHeaderTableView()
@property (nonatomic ,strong) NSString *text;
@end
@implementation STApplicationFormHeaderTableView
- (void)commitInit {
    [super commitInit];
    
    [self setHeader];
    
    [self setFooter];
}
- (void)setHeader {
    
    UIView *header = [UIView new];
    
    header.frame = CGRectMake(0, 0, ST_SCREEN_WIDTH, 20 * ST_RATE);
    
    self.tableHeaderView = header;
}

- (void)setFooter {
    CGFloat margin = 20 * ST_RATE;
    
    CGFloat height = 90 * ST_RATE;
    
    self.text = @"是否三证合一";
    
    UIView *footer = [UIView new];
    
    footer.frame = CGRectMake(0, 0, ST_SCREEN_WIDTH, height);
    
    UILabel *footerLabel = [UILabel new];
    
    footerLabel.textColor = ST_EE7D21_COLOR;
    
    footerLabel.text = self.text;
    
    footerLabel.frame = CGRectMake(margin, 0, ST_SCREEN_WIDTH , height);
    
    [footer addSubview:footerLabel];
    
    footer.backgroundColor = ST_WHITE_COLOR;
    
    UISwitch *swi = [[UISwitch alloc]init];
    
    [footer addSubview:swi];
    
    [swi addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
    
    [swi mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(120 * ST_RATE);
        make.height.equalTo(50 * ST_RATE);
        make.right.equalTo(-30 * ST_RATE);
        make.top.equalTo(15 * ST_RATE);
    }];
    
    self.tableFooterView = footer;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 20 * ST_RATE;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [tableView deselectRowAtIndexPath:indexPath animated:true];
    
    [self.mDelegate onItemClick:STItemClickTypeItemMaterial withData:self.dataArray[indexPath.row] forIndexPath:indexPath];
}

- (void)valueChanged:(UISwitch *)sender {
    
    sender.selected = !sender.selected;
    
    [self.mDelegate onItemClick:STItemClickTypeSwitch withData:@(sender.selected) forIndexPath:nil];
}
@end
